package com.woniuxy.cloud.batteryassembly.controller;


import com.woniuxy.cloud.api.BatteryTypeApi;
import com.woniuxy.cloud.batteryassembly.service.IBatteryTypeService;
import com.woniuxy.cloud.demo.Result;
import com.woniuxy.cloud.dto.BatteryTypeDto;
import com.woniuxy.cloud.param.BatteryTypeParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaorui
 * @since 2022-02-09
 */
@RestController
public class BatteryTypeController implements BatteryTypeApi {

    @Resource
    private IBatteryTypeService  batteryTypeService;

    @Override//根据ID批量查询电池类型
    public Result findBatteryType(List<Integer> ids) {
        return new Result().newInstance().setMsg("查询成功").setCode(200).setData(batteryTypeService.findBatteryType(ids));
    }


    @PostMapping("/listBatteryType")
    public Result listBatteryType() {
        return new Result().newInstance().setMsg("查询成功").setCode(200).setData(batteryTypeService.listBatteryType());
    }

    @PostMapping("/addNewBatteryType")
    public Result<BatteryTypeDto> addNewBatteryType(@RequestBody @Validated BatteryTypeParam param) {
        BatteryTypeDto dto= batteryTypeService.addNewBatteryType(param);
        return new Result().newInstance().setMsg("添加成功").setCode(200).setData(dto);
    }


    @PostMapping("/listBatteryTypeByLocationId/{locationId}")
    public Result listBatteryTypeByLocationId(@PathVariable Integer locationId) {
        return new Result().newInstance().setMsg("查询成功").setCode(200).setData(batteryTypeService.listBatteryTypeByLocationId(locationId));
    }

}

